package com.lanmao.blog.service.impl;

import com.lanmao.blog.service.LoginService;
import com.lanmao.blog.utils.BLOG_CONSTANT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Override
    public String phonelogin(String phone, String code) {
        String redisinfo = stringRedisTemplate.opsForValue().get(BLOG_CONSTANT.PHONE_CACHE + phone);
        if (redisinfo==null||redisinfo.isEmpty()){
            return "该用户不存在或验证码过期";
        }
        String rediscode = redisinfo.split("_")[0];
        if (rediscode.equals(code)){//与redis中的验证码一致，给予登录
            stringRedisTemplate.delete(BLOG_CONSTANT.PHONE_CACHE+phone);
            return "1";
        }else{//不一致，不登陆
            return "验证码错误";
        }

    }


}
